# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=fonttools
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=4.58.0
pkgrel=1
pkgdesc="Converts OpenType and TrueType fonts to and from XML (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: python-fonttools'
  'purl: pkg:pypi/fonttools'
)
msys2_repository_url='https://github.com/fonttools/fonttools/'
url='https://fonttools.readthedocs.io/'
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
if [[ ${CARCH} != i686 ]]; then
optdepends=("${MINGW_PACKAGE_PREFIX}-python-brotli: WOFF 1.0 and WOFF 2.0 webfonts"
            "${MINGW_PACKAGE_PREFIX}-python-pyfilesystem2: for fontTools.ufoLib: to read/write UFO fonts"
            "${MINGW_PACKAGE_PREFIX}-python-pyzopfli: WOFF 1.0 and WOFF 2.0 webfonts"
            "${MINGW_PACKAGE_PREFIX}-python-sympy: for fontTools.misc.symfont, module for symbolic font statistics analysis"
            "${MINGW_PACKAGE_PREFIX}-python-matplotlib: for visualizing DesignSpaceDocument and resulting VariationModel")
fi
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pyfilesystem2"
              "${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-brotli"
              "${MINGW_PACKAGE_PREFIX}-python-ufolib2")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('27423d0606a2c7b336913254bf0b1193ebd471d5f725d665e875c5e88a011a43')

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

#Enable tests when the dependencies are solved
check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  PYTHONPATH=Lib ${MINGW_PREFIX}/bin/python -m pytest || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -D -m755 LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/python-${_realname}/LICENSE
  chmod oga+r "${pkgdir}${MINGW_PREFIX}"/share/man/man1/ttx.1
}
